package com.eazyimage.lab.controller;

import com.eazyimage.lab.entity.Response;
import com.eazyimage.lab.service.DatasetMessService;
import com.eazyimage.lab.service.Verifygenservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.eazyimage.lab.entity.Dataset_;
import java.util.List;

@RestController
public class VerifygenController {
    @Autowired
    Verifygenservice vs;
    @Autowired
    DatasetMessService sv;
    @RequestMapping("/GenerateVerify")
    @ResponseBody
    String GenerateVerify(@RequestParam("Datasetid") int datasetid)
    {
        return vs.Generateverify(datasetid);
    }

    @RequestMapping("/getfigure")
    @ResponseBody
    public String getdatasetmess(@RequestParam("verify") String verify){
        try{
            Dataset_ data = vs.Findbyverify(verify);
            String form = "";
            form += "# server<br>";
            form += "server.url = http://116.62.23.69:8081/dataset_upload/<br>";
            form += "server.verify = " + verify+"<br>";
            form += "server.dataSet.name = " + data.getDatasetName() + "<br>";
            form += "server.dataSet.id = " + data.getDatasetid() + "<br>";
            form += "<br># photo<br>";
            form += "photo.width = " + data.getPhoto_width()+"<br>";
            form += "photo.height = " + data.getPhoto_height()+"<br>";
            form += "<br># label<br>";
            form += "label.list = " + data.getLabel_list()+"<br>";
            form += "label.default = " + data.getLabel_default()+"<br>";
            form += "<br># view<br># 九宫格<br>view.showT9 = true<br># 水平仪<br>view.showLevel = true";
            return form;
        }catch(NullPointerException e)
        {
            return "fail，未找到对应校验码";
        }
    }
    @RequestMapping("/getdescription")
    @ResponseBody
    public String getdatasetdes(@RequestParam("verify") String verify){
        try{
            Dataset_ data = vs.Findbyverify(verify);
            String form = "";
            form += data.getDatasetDescription();
            return form;
        }catch(NullPointerException e)
        {
            return "fail，未找到对应校验码";
        }
    }

    @RequestMapping("/getpublicdatasetmess")
    public Response getpublicdatasetmess(){
        try {
            List<Dataset_> datamess = vs.Findbyispublic();
            return Response.success(datamess);
        } catch (Exception e) {
            return Response.fail();
        }
    }

    @RequestMapping("/Selectpublicnum")
    public Response Selectpublicnum(){
        try {
            return Response.success(vs.getpublicdatasetid());
        } catch (Exception e) {
            return Response.fail();
        }
    }
}
